package com.qinyunkj.searchchatserver.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qinyunkj.searchchatserver.model.common.Result;
import com.qinyunkj.searchchatserver.model.dto.ArticleQAQuery;
import com.qinyunkj.searchchatserver.model.entity.ArticleQA;
import com.qinyunkj.searchchatserver.model.enums.SceneType;
import com.qinyunkj.searchchatserver.model.vo.ArticleQAStatistics;
import com.qinyunkj.searchchatserver.model.vo.ArticleQAVO;
import com.qinyunkj.searchchatserver.service.ArticleQAService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "问答管理接口")
@RestController
@RequestMapping("/api/qa")
@RequiredArgsConstructor
public class ArticleQAController {

    private final ArticleQAService articleQAService;

    @Operation(summary = "分页查询问答列表")
    @GetMapping
    public Result<IPage<ArticleQAVO>> getQAPage(ArticleQAQuery query) {
        return Result.success(articleQAService.getQAPage(query));
    }

    @Operation(summary = "获取问答详情")
    @GetMapping("/{id}")
    public Result<ArticleQA> getById(@PathVariable Long id) {
        return Result.success(articleQAService.getById(id));
    }

    @Operation(summary = "创建问答")
    @PostMapping
    public Result<Void> create(@RequestBody ArticleQA articleQA) {
        articleQAService.create(articleQA);
        return Result.success();
    }

    @Operation(summary = "更新问答")
    @PutMapping("/{id}")
    public Result<Void> update(@PathVariable Long id, @RequestBody ArticleQA articleQA) {
        articleQA.setId(id);
        articleQAService.update(articleQA);
        return Result.success();
    }

    @Operation(summary = "删除问答")
    @DeleteMapping("/{id}")
    public Result<Void> delete(@PathVariable Long id) {
        articleQAService.delete(id);
        return Result.success();
    }

    @Operation(summary = "获取问答统计信息")
    @GetMapping("/statistics")
    public Result<ArticleQAStatistics> getStatistics() {
        return Result.success(articleQAService.getStatistics());
    }

    @Operation(summary = "获取所有场景类型")
    @GetMapping("/scene-types")
    public Result<List<SceneType>> getAllSceneTypes() {
        return Result.success(SceneType.getAllSceneTypes());
    }
}
